<template>
  <z-dict-select-tag
    :value="value"
    v-bind="cellProps"
    :getPopupContainer="getPopupContainer"
    :triggerChange="true"
    @change="handleSelectChange"
  />
</template>

<script>
import ZDictSelectTag from '@/components/dict/ZDictSelectTag'
import { initDictOptions, filterDictText } from '@/components/dict/ZDictSelectUtil'
export default {
  name: 'VxeSelectCell',
  components: {
    ZDictSelectTag
  },
  props: {
    value: [String, Number],
    params: Object,
    renderOptions: Object,
    cellProps: Object
  },
  methods: {
    handleSelectChange(val) {
      const { row, column, $table } = this.params
      this.$set(row, column.property, val)
      $table.updateStatus(this.params)
    },
    getPopupContainer() {
      return document.body
    }
  },
  enhanced: {
    translate: {
      // 是否启用翻译
      enabled: true,
      async handler(value) {
        // 默认翻译方法
        const res = await initDictOptions(this.cellProps.dictCode)
        return res.success ? filterDictText(res.result.items, value) : ''
      }
    }
  }
}
</script>
